<?php
namespace app\admin\controller;

use think\Db;
use think\Log;

class Upload extends Admin
{
    public function index()
    {
        return $this->view->fetch();
    }

    /**
     * 文件上传
     */
    public function upload()
    {
        $file = $this->request->file('file');
        $path = ROOT_PATH . 'uploads/';
        $info = $file->move($path);

        $data = $this->request->root() . '/uploads/' . $info->getSaveName();
        $insert = [
            'name' => $data,
            'type' => 3,
            'file_name' => $info->getInfo('name'),
            'file_type' => $info->getInfo('type'),
            'file_size' => $info->getInfo('size'),
            'add_time' => time(),
        ];
        Db::name('upfiles')->insert($insert);
        return ajax_return('', ['name' => $data]);
    }
}